package com.trw.trp.action;

import java.io.IOException;
import java.util.List;

import com.trw.trp.bean.PropertyBean;
import com.trw.trp.dao.DaoFactory;
import com.trw.trp.dao.SystemSettingDao;
import com.trw.trp.msg.ResultMessage;

public class SystemSettingAction extends AbstractAction {

	public void getProperties() throws IOException {
		SystemSettingDao dao = DaoFactory.getSystemSettingDao();
		List<PropertyBean> propList = dao.getProperties();
		writeJSON(propList);
	}

	public void updateProperties() throws IOException {
		SystemSettingDao dao = DaoFactory.getSystemSettingDao();
		List<PropertyBean> propList = dao.getProperties();
		if (propList != null) {
			for (PropertyBean bean : propList) {
				bean.setValue(getValue(bean.getId()));
			}
		}
		dao.updateProperties(propList);
		ResultMessage msg = new ResultMessage();
		msg.setState(ResultMessage.SUCCESS);
		writeJSON4Form(true, msg);
	}

	private String getValue(long propId) {
		return getParamFromRequest("p_" + propId);
	}

}
